<!DOCTYPE html>
<title>Selection of vertical text</title>
<script src="../../resources/ahem.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<style>body { margin: 0; }</style>
<svg width="300" height="300">
  <text id="text1" x="20" y="20" writing-mode="vertical-lr"
        font-family="Ahem" font-size="20">MMMMM MMMMMMMM</text>
</svg>
<script>
function selectText(start, end) {
  let startPoint = { x: 10 + 10, y: 20 + start * 20 + 8 };
  let endPoint = { x: 10 + 10, y: 20 + (end + 1) * 20 - 8 };
  const leftButton = 0;

  assert_own_property(window, 'chrome');
  assert_own_property(window.chrome, 'gpuBenchmarking');
  return new Promise(function(resolve, reject) {
    chrome.gpuBenchmarking.pointerActionSequence(
      [{
        source: 'mouse',
        actions: [
          { name: 'pointerMove', x: startPoint.x, y: startPoint.y },
          { name: 'pointerDown', x: startPoint.x, y: startPoint.y, button: leftButton },
          { name: 'pointerMove', x: endPoint.x, y: endPoint.y },
          { name: 'pointerUp', button: leftButton }
        ]
      }], resolve);
  });
}

promise_test(function() {
  return selectText(0, 0).then(() => {
    var range = window.getSelection().getRangeAt(0);
    assert_equals(range.startOffset, 0);
    assert_equals(range.endOffset, 1);
  });
}, document.title+', start of text');

promise_test(function() {
  return selectText(4, 7).then(() => {
    var range = window.getSelection().getRangeAt(0);
    assert_equals(range.startOffset, 4);
    assert_equals(range.endOffset, 8);
  });
}, document.title+', middle of text');

promise_test(function() {
  return selectText(13, 13).then(() => {
    var range = window.getSelection().getRangeAt(0);
    assert_equals(range.startOffset, 13);
    assert_equals(range.endOffset, 14);
  });
}, document.title+', end of text');
</script>
